<template>
  <div>
    <h1>当前的值：{{ $store.state.count }}  {{$store.getters.oddOrEven}} </h1>
    <select v-model="val">
      <option :value="1">1</option>
      <option :value="2">2</option>
      <option :value="3">3</option>
      <option :value="4">4</option>
    </select>
    <button @click="handleIncrement">+</button>
    <button @click="handleDecrement">-</button>
    <button @click="handleIfOddIncrement">如果是奇数就加</button>
    <button @click="handleIncrementAsync">延迟1s加</button>
    
  </div>
</template>

<script>

export default {
  name: "App",
  data(){
    return {
      val: 1,
    }
  },
  methods:{
    handleIncrement(){
      this.$store.dispatch("increment",this.val);
    },
    handleDecrement(){
       this.$store.dispatch("decrement",this.val);
    },
    handleIfOddIncrement(){
      this.$store.dispatch("ifoddincrement",this.val);

      /* if(this.$store.state.count % 2 === 1){
        handleIncrement();
      } */
    },
    handleIncrementAsync(){
      this.$store.dispatch("incrementAsync",this.val);
    }
  }
};

</script>

